﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Security;
using MyBBS.Data.Interfaces;
using MyBBS.Data;
using MyBBS.Data.Models;

namespace MyBBS.Services
{
    public class UserService : IUserService
    {
        private IUserRepository _userRepository;

        
        public UserService(IUserRepository userRepository)
        {
            _userRepository = userRepository;
        }
        #region IUserService Members

        /// <summary>
        /// Sign up a new user
        /// </summary>
        /// <param name="userName">User's Name</param>
        /// <param name="password">User's Password</param>
        /// <param name="email">User's email</param>
        /// <returns>MembershipCreateStatus, the create status</returns>
        public MembershipCreateStatus SignUp(string userName, string password, string email)
        {
            User user = new User() { UserName = userName, Password = password, Email = email };

            return _userRepository.SignUp(user);
        }


        /// <summary>
        /// Login 
        /// </summary>
        /// <param name="userName">User's Name</param>
        /// <param name="password">User's Password</param>
        /// <returns>true, if userName and password match; else false</returns>
        public bool Login(string userName, string password)
        {
            return _userRepository.Login(userName, password);
        }

        public User GetUserByUserName(string userName)
        {
            return _userRepository.GetUserByUserName(userName);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool Logout()
        {
            try
            {
                _userRepository.Logout();
            }
            catch
            {
                return false;
            }

            return true;
        }
        #endregion
    }
}
